<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>login</title>
</head>

<body>
    <%- include common %>
    <%- include('head',{title:'登录'}) %>
    <form action="/users/login" method="get">
        <h2>欢迎登陆</h2>
        <div>
            <label for="username">
                <input type="text" id="username" value="<%- username %>" placeholder="请输入用户名" name="username">
            </label>
        </div>
        <div>
            <label for="password">
                <input type="password" id="password" placeholder="请输入密码" name="pass">
            </label>
        </div>
        <div>
            <button type="submit"> 提交登录</button>
            <button type="reset">重置</button>
            <button type="button" id="mybtn"> ajax登录</button>
        </div>
    </form>


    <!-- <%- include('foot') %> -->
    <%- include foot %>
    <script>
        $('#mybtn').click(function () {
            $.ajax({
                url: '/users/signin',
                type: 'POST',
                data: {
                    username: $('#username').val(),
                    pass: $('#password').val()
                },
                success: res => {
                    console.log(res);
                    const {code ,msg} = res
                    alert(msg)
                    if(code==200){
                        location.href = '/'
                    }
                }
            })
        })
    </script>
</body>

</html>